package com.yswl.yeeduo.ui.activity;

import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import cn.jpush.android.api.JPushInterface;

import com.umeng.analytics.AnalyticsConfig;
import com.umeng.analytics.MobclickAgent;
import com.yswl.yeeduo.R;
import com.yswl.yeeduo.base.KActivity;
import com.yswl.yeeduo.tool.KLog;
import com.yswl.yeeduo.ui.tool.AppManager;
import com.yswl.yeeduo.ui.tool.PositionUtil;

public class WelcomeActivity extends KActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFormat(PixelFormat.RGBA_8888);
		View view = View.inflate(this, R.layout.activity_welcome, null);
		setContentView(view);

		MobclickAgent.setDebugMode(KLog.isShow);// 友盟测试
		MobclickAgent.openActivityDurationTrack(false);// 友盟统计因app包含fragment 需要禁止
		MobclickAgent.updateOnlineConfig(this);
		AnalyticsConfig.enableEncrypt(false);// 发送日志加密

		Animation animation = new AlphaAnimation(0.2f, 1f);
		animation.setDuration(2000);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				next();
			}

		});
		
	
		
		if (KLog.isShow == true) {
			/**
			 * android 性能调优
			 */
			StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // 这里可以替换为detectAll()
																																	// 就包括了磁盘读写和网络I/O
					.penaltyLog() // 打印logcat，当然也可以定位到dropbox，通过文件保存相应的log
					.build());
			// StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
			// .detectLeakedSqlLiteObjects() //探测SQLite数据库操作
			// .penaltyLog() //打印logcat
			// .penaltyDeath()
			// .build());

		}
		view.startAnimation(animation);

	}

	private void next() {
		if (AppManager.isFirstOpenApp(this)) {
			startActivity(new Intent(this, GuideActivity.class));
		} else {
			startActivity(new Intent(this, MainActivity.class));
		}
		overridePendingTransition(R.anim.activity_push_up_in, R.anim.activity_push_up_out);
		finish();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			exitApp();
		}
		return true;
	}

	// Um
	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart(this.getClass().getSimpleName());
		MobclickAgent.onResume(this); // 统计时长
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd(this.getClass().getSimpleName());
		MobclickAgent.onPause(this);
	}
}
